#include<stdio.h>
#include<stdlib.h>

 void qsort(void *base, size_t nmemb, size_t size,
                   int(*compar)(const void *, const void *));

int cmp(const void *a, const void *b)
{
	const int *ai = a, *bi = b;
	return *ai - *bi;
}

int is_straight(int *data, int n)
{
	int zero_n = 0, gap_n = 0, i;

	if(data == NULL)
		return 0;

	qsort(data, n, sizeof(int), cmp);
	
	i = 0;
	while (data[i] == 0 && i < n) {
		zero_n ++;
		i++;
	}
	if (i == n - 1) /* only remains one */
		return 1;

	while (i < n - 1) {
		printf("i:%d::%d::%d\n", i, data[i], data[i + 1]);
		if (data[i] != data[i + 1] - 1)
			gap_n += data[i + 1] - data[i] - 1;
		i++;
	}
	printf("gap_n:%d:zero_n:%d\n", gap_n, zero_n);
	return gap_n <= zero_n;
}

int main() 
{
	int data[] = {5, 0, 2, 1, 4};
	return is_straight(data, 5);
}
